//
//  DDMainMusicCellViewModel.m
//  DDMusic
//
//  Created by rimi on 16/11/9.
//  Copyright © 2016年 FengBaoFamily. All rights reserved.
//
/******************这是首页app音乐视图模型********************/
#import "DDMainMusicCellViewModel.h"
#import "DDNetWorkTools.h"
#import "DDPublicMacro.h"
#import <AVOSCloudSNS.h>
#import <AVQuery.h>
#import "DDMusicModel.h"
@implementation DDMainMusicCellViewModel
- (void)loadDataWithStyle:(DDMainMusicCellDataStyle)style isOK:(void (^)(BOOL, NSError *))isOk{
    if (style == HotMusicDataStyle) {
//热门歌曲
        [[DDNetWorkTools shareDDNetWorkTools]requestWithMethod:POST Url:QQMUSICREQUESTURI Parameters:@{@"topid":@26,@"showapi_appid":SHOWAPI_APPID,@"showapi_sign":SHOWAPI_SIGN} finished:^(id responseObject, NSError *error) {
        if (error){
            isOk(NO,error);
        }else{
            self.hotMusicModels = [NSMutableArray array];
            NSArray* musicArr = responseObject[@"showapi_res_body"][@"pagebean"][@"songlist"];
            for (NSDictionary* dic in musicArr) {
              DDMusicModel* model = [[DDMusicModel alloc]initWithDic:dic];
                [self.hotMusicModels addObject:model];
            }
            isOk(YES,nil);
        }
        }];
    }else if (style == RecommendMusicDataStyle){

        AVQuery* query = [AVQuery queryWithClassName:@"RecommendMusic"];
       __weak DDMainMusicCellViewModel* weakSelf = self;
        [query getObjectInBackgroundWithId:@"5823bca72e958a12992399b3" block:^(AVObject *object, NSError *error) {
            if (error) {
                isOk(NO,error);
            }else{
                self.recommendMusicModels = [NSMutableArray array];
                NSArray* arr = (NSArray*)object[@"muscis"];
                for (NSDictionary*dic in arr) {
                    DDMusicModel* model = [[DDMusicModel alloc]initWithDic:dic];
                    [weakSelf.recommendMusicModels addObject:model];
                    isOk(YES,nil);
                }
                
            }
        }];
    }
    
           
}
@end
